<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="招标项目编号">
              <j-input placeholder="请输入招标项目编号" v-model="queryParam.tenderProjectCode"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="文件编号">
              <j-input placeholder="请输入文件编号" v-model="queryParam.docNo"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="文件名称">
              <j-input placeholder="请输入文件名称" v-model="queryParam.docName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a-button @click="handleAdd" type="primary" icon="plus" style="margin-left: 8px">新增</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <!-- <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
    </div> -->

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text, record">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            :preview="record.id"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <!-- <template slot="fileSlot" slot-scope="text, record">
          <a-button :ghost="true" type="primary" icon="download" size="small" @click="doDownloadFile(record)">
            下载
          </a-button>
        </template> -->
        <span slot="downloadAttachment" slot-scope="text,record">

        </span>
        <span slot="docNo" slot-scope="text, record">
          {{text}}
          <a-icon @click="editDocNo(record)" type="edit" />
        </span>
        <span slot="action" slot-scope="text, record">
          <template v-if="record.status != 2">
            <a-popconfirm title="发布后不能再做编辑，确定发布吗?" @confirm="() => handlePublish(record)">
              <a>发布</a>
            </a-popconfirm>
            <a-divider type="vertical" />
            <a @click="handleEdit(record)">编辑</a>
          </template>
          <template v-else>
            <a disabled="disabled">发布</a><a-divider type="vertical" /> <a disabled="disabled">编辑</a
            >
          </template>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link"> 更多 <a-icon type="down" /> </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a href="javascript:;" @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item :disabled="record.status == 2">
                <a-popconfirm
                  title="确定删除吗?"
                  @confirm="() => handleDelete(record.id)"
                >
                  <a :disabled="record.status == 2">删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <SelectList ref="selectPrjectRef" @ok="selectPrjectOk" :projectId="projectId"></SelectList>
    <add-modal ref="addModal"></add-modal>

    <j-modal
      :visible="downloadVisible"
      :confirmLoading="downloadLoading"
      @ok="confirmDownload"
      @cancel="downloadCancel"
    >
      <a-spin :spinning="loading">
        <a-form-model ref="form" :labelCol="{ span: 4 }" :wrapperCol="{ span: 20 }">
          <a-form-model-item label="联系人">
            <a-input ref="input" v-model="downloadForm.downloadUserName" />
          </a-form-model-item>
          <a-form-model-item label="电话">
            <a-input ref="input" v-model="downloadForm.downloadUserPhone" />
          </a-form-model-item>
        </a-form-model>
      </a-spin>
    </j-modal>
    <EditDocModal ref="editDocRef" @refresh="searchQuery"/>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import SelectList from '@/views/exProject/SelectList'
import { postAction, getAction, downloadFile } from '@/api/manage'
import AddModal from '@/views/exTenderFile/AddModal'
import EditDocModal from './EditDocModal.vue'
import moment from 'dayjs'

export default {
  name: 'ExTenderFileClariModiList',
  mixins: [JeecgListMixin, mixinDevice],
  props:{projectId:{}},
  components: { SelectList, AddModal, EditDocModal },
  data() {
    return {
      description: '招标文件管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '招标项目编号',
          align: 'center',
          dataIndex: 'tenderProjectCode',
        },
        {
          title: '标段（包）编号',
          align: 'center',
          dataIndex: 'bidSectionCode',
        },
        {
          title: '文件编号',
          align: 'center',
          dataIndex: 'docNo',
          scopedSlots: { customRender: 'docNo' },
        },
        //    {
        //   title: '文件',
        //   align: 'center',
        //   dataIndex: 'downloadAttachment',
        // },
        {
          title: '文件下载截止日期',
          align: 'center',
          dataIndex: 'downloadEndTime',
        },
        // {
        //   title: '附件',
        //   align: 'center',
        //   dataIndex: 'downloadAttachment',
        //   scopedSlots: { customRender: 'downloadAttachment' },
        // },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'status_dictText',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/exTenderFileClariModi/exTenderFileClariModi/list',
        delete: '/exTenderFileClariModi/exTenderFileClariModi/delete',
        deleteBatch: '/exTenderFileClariModi/exTenderFileClariModi/deleteBatch',
        exportXlsUrl: '/exTenderFileClariModi/exTenderFileClariModi/exportXls',
        importExcelUrl: 'exTenderFileClariModi/exTenderFileClariModi/importExcel',
        queryProjectDetail: '/exProject/exProject/queryById',
        downloadRecord: '/exProject/exZbfileDownloadrecord/add',
      },
      dictOptions: {},
      superFieldList: [],
      projectInfo: {},
      downloadVisible: false,
      downloadLoading: false,
      downloadForm: {
        downloadUrl: '',
        downloadUserName: '',
      },
    }
  },
  watch: {
    projectId: {
      immediate: true,
      handler(val) {
        this.getProjectDetail()
      },
    },
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    editDocNo (record) {
      console.log(1)
      this.$refs.editDocRef.showModal(record)
    },
    getProjectDetail() {
      var that = this
      this.queryParam.projectId = that.projectId
      this.loadData()

      // getAction(this.url.queryProjectDetail, { id: this.projectId }).then((res) => {
      //   if (res.success) {
      //     this.projectInfo = res.result

      //   }
      // })
    },
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'tenderProjectCode', text: '招标项目编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bidSectionCode', text: '标段（包）编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'docNo', text: '文件编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'docName', text: '文件名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'url', text: '文件源url', dictCode: '' })
      fieldList.push({
        type: 'string',
        value: 'status',
        text: '状态(0-保存 1-送审 2-通过 3-驳回)',
        dictCode: 'sys_common_status',
      })
      fieldList.push({ type: 'Text', value: 'docContent', text: '内容', dictCode: '' })
      this.superFieldList = fieldList
    },
    handleAdd() {
      // debugger
      this.$refs.selectPrjectRef.show()
      //this.$router.push({ path: '/exTenderFile/add' })
    },
    handleEdit(row) {
      //this.$router.push({ path: '/exTenderFile/add', query: { exTenderFileId: row.id } })
      this.$refs.addModal.edit(row)
    },
    handleDetail(row) {
      //this.$router.push({ path: '/exTenderFile/add', query: { exTenderFileId: row.id } })
      this.$refs.addModal.edit(row)
      this.$refs.addModal.title="详情";
      this.$refs.addModal.disableSubmit = true;

    },
    handlePublish(row) {
      //发布
      var that = this
      var param = {
        id: row.id,
        status: 2,
      }
      postAction('exTenderFileClariModi/exTenderFileClariModi/updateStatus', param)
        .then((res) => {
          if (res.success) {
            that.$message.success('操作成功')
            that.loadData()
          } else {
            that.$message.warning(res.message)
          }
        })
        .finally(() => {
          that.confirmLoading = false
        })
    },
    selectPrjectOk(selectObj) {
      var that = this
      var param = {
        projectId: selectObj['sectionInfo'].projectId,
        sectionId: selectObj['sectionInfo'].id,
        bidSectionCode: selectObj['sectionInfo'].bidSectionCode,
        tenderProjectCode: selectObj['projectInfo'].projectCode,
      }
      postAction('exTenderFileClariModi/exTenderFileClariModi/add', param)
        .then((res) => {
          if (res.success) {
            that.$message.success('操作成功')
            that.loadData()
          } else {
            that.$message.warning(res.message)
          }
        })
        .finally(() => {
          that.confirmLoading = false
        })
    },
    doDownloadFile(record) {
      let param = { sectionId: record.sectionId }
      var exportUrl = '/exTenderFileClariModi/exTenderFileClariModi/download/zbFile'
      downloadFile(exportUrl, 'aa.zip', param, 'get')
    },
    searchReset() {
      this.queryParam = { projectId: this.projectId }
      this.loadData()
    },
    showDownloadModal(record) {
      this.downloadVisible = true
      this.downloadForm.bidSectionId = record.sectionId
      this.downloadForm.dowdloadDate = moment(new Date()).format('YYYYMMDDHHmmss')
      this.downloadForm.dataTimestamp = moment(new Date()).format('YYYYMMDDHHmmss')
    },
    downloadCancel() {
      this.downloadVisible = false
    },
    confirmDownload() {
      if (!this.downloadForm.downloadUserName) {
        this.$message.warning('请输入联系人姓名')
        return
      }
      postAction(this.url.downloadRecord, this.downloadForm)
        .then((res) => {
          console.log(res)
          this.doDownloadFile({
            sectionId: this.downloadForm.sectionId,
          })
        })
        .finally(() => {
          that.confirmLoading = false
        })
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
